﻿using System;

namespace NEnsure.Rules
{
	public class UniqueRule : BaseBusinessRule<string>, IBusinessRule<string>
	{
		private Predicate<string> _isValueInUse;

		public override string RuleKey
		{
			get { return "Unique Rule"; }
		}

		public UniqueRule(Predicate<string> isValueInUseChecker)
			: base("{value} is already in use.")
		{
			_isValueInUse = isValueInUseChecker;
		}

		public bool IsBrokenBy(string value)
		{
			return _isValueInUse(value);
		}
	}
}
